﻿using Microsoft.Practices.Unity;
using SportTraining.Core.Dal;
using SportTraining.Core.Linq2Sql;
using SportTraining.Core.Linq2Sql.Dal;
using SportTraining.Core.Services;
using SportTraining.MVVM.Model;
using SportTraining.MVVM.Model.Impl;
using SportTraining.MVVM.ViewModel;
using SportTraining.MVVM.ViewModel.Impl;
using SportTraining.Services;
using TermClasses;

namespace SportTraining.Helpers
{
    public abstract class ContainerHelper
    {
        public static IUnityContainer CreateContainer()
        {
            Logger.Log.Info("Создание контейнера начато...");

            IUnityContainer container = new UnityContainer();

            #region register Dal

            container.RegisterType<IDataContext, SportTrainingDataContext>(new ContainerControlledLifetimeManager(),
                                                                           new InjectionConstructor(true));
            container.RegisterType<ISectionDal, SectionDal>();
            container.RegisterType<IPaymentDal, PaymentDal>();

            #endregion

            #region b.. model

            container.RegisterType<IPaymentProcedureModel, PaymentProcedureModel>(new ContainerControlledLifetimeManager());

            #endregion

            #region view model

            container.RegisterType<IMainWindowViewModel, MainWindowViewModel>(new ContainerControlledLifetimeManager());
            container.RegisterType<IMainPageViewModel, MainPageViewModel>(new ContainerControlledLifetimeManager());

            container.RegisterType<ISectionSelectPageViewModel, SectionSelectPageViewModel>();
            container.RegisterType<IPaymentPageViewModel, PaymentPageViewModel>();
            container.RegisterType<IErrorPageViewModel, ErrorPageViewModel>();

            #endregion

            #region terminal device + service for terminal device

            container.RegisterType<IBillAcceptor, BillAcceptor>(new ContainerControlledLifetimeManager());
            container.RegisterType<IFiscalRegister, FiscalRegister>(new ContainerControlledLifetimeManager());
#if DEBUG
            container.RegisterType<ITerminalBillValidator, TermClasses.Mock.CashCodeSMBillValidator>(new ContainerControlledLifetimeManager());
            container.RegisterType<ITerminalFiscalRegister, TermClasses.Mock.ShtrihMiniFiscalRegister>(new ContainerControlledLifetimeManager());
#else
            container.RegisterType<ITerminalBillValidator, TermClasses.CashCodeSMBillValidator>(new ContainerControlledLifetimeManager());
            container.RegisterType<ITerminalFiscalRegister, TermClasses.ShtrihMiniFiscalRegister>(new ContainerControlledLifetimeManager());
#endif
            #endregion

            Logger.Log.Info("Создание контейнера завершено.");

            return container;
        }
    }
}
